import React from 'react';

export default class UnitSettingList extends React.Component {
  constructor(props) {
    super(props)
  }

  renderList() {
    var self = this;
    var content = [];
    if (this.props.data && this.props.data.length > 0) {
      this.props.data.forEach(function(data, index) {
        var property = data.property
        content.push((
          <tr>
            <td>{data.unit_number}</td>
            <td>{data.unit_desc}</td>
            <td>{property?property.name:""}</td>
            <td>{data.sys_user?data.sys_user.firstName+" "+data.sys_user.lastName: ""}</td>
            <td>
              <a className="f-dn" onClick={(event)=>self.props.onDeleteClick(data.id)}>删除</a>
              <a className="edit f-dn" onClick={(event)=>self.props.onEditClick(data)}>编辑</a>
              <a className="edit" onClick={(event)=>self.props.onDetailClick(data.unit_number)}>查看绑定情况</a>
            </td>
          </tr>
        ))
      })
    }

    return content
  }

  render() {
    return(
      <div className="unit-setting-list setting-list">
        <table className="table">
          <thead>
            <tr className="table-title">
              <th className="id">ID</th>
              <th className="no">户号</th>
              <th className="name">物业</th>
              <th className="admin">管家客服</th>
              <th className="edit">操作</th>
            </tr>
          </thead>
          <tbody>
            {this.renderList()}
          </tbody>
        </table>
      </div>
    )
  }
}
